/*
 *  Copyright 2009 David Kuhn <david.s.kuhn at gmail.com>.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package com.google.code.teamtools.client.controller;

import com.google.code.teamtools.client.view.*;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.google.code.teamtools.client.AppEvents;

/**
 * 
 * @author David Kuhn <david.s.kuhn at gmail.com>
 */
public class TeamController extends Controller
{
    private TeamHierarchyView teamHierarchyView;
    private EditorView editorView;

    public TeamController()
    {
        registerEventTypes(AppEvents.Init);
        registerEventTypes(AppEvents.Open);
        registerEventTypes(AppEvents.NavTeam);
    }

    @Override
    public void handleEvent(AppEvent event)
    {
        EventType type = event.getType();
        if (type == AppEvents.Init) {
            forwardToView(teamHierarchyView, event);
        } else if (type == AppEvents.NavTeam) {
            forwardToView(teamHierarchyView, event);
            forwardToView(editorView, event);
        } else if (type == AppEvents.Open) {
            forwardToView(editorView, event);
        }
    }

    public void initialize()
    {
        super.initialize();

        teamHierarchyView = new TeamHierarchyView(this);
        editorView = new EditorView(this);
    }
}
